package org.demo.kafka.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class KafkaProducer {
    private static final String KAFKA_TOPIC="testDemo"; //主题
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    /**
     * 发送消息到kafka
     *@param message 内容体
     */
    public void sendMsg( String message){
        kafkaTemplate.send(KAFKA_TOPIC ,message);
    }
}
